package com.kfm.am.exec;

import java.io.File;
import java.util.List;
import java.util.function.BinaryOperator;
import java.util.function.LongBinaryOperator;

public class Exec02 {

    public static void main(String[] args) {
        String pathname = "E:/Image";
//        System.out.println(new File(pathname).length() / 1024.0);
        System.out.println(getSize2(pathname) / 1024.0 / 1024);
    }

    private static long getSize(String pathname) {
        List<File> allFiles = Exec01.getAllFiles(pathname);
        long size = 0l;
        for (File file :allFiles) {
            if (file.isFile()) {
                size += file.length();
            }
        }
        return size;
    }

    private static long getSize2(String pathname) {
        List<File> allFiles = Exec01.getAllFiles(pathname);
        return allFiles.stream().mapToLong(f -> f.length()) // 将文件的大小变成一个新的流
                .reduce((l1, l2) -> l1+ l2).orElse(0);
    }
}
